home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / redo / redoCheckPage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.5 KB  |  225 lines

  1. /*
  2.  *   $RCSfile: redoCheckPage.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:58 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "log.h"
  57. #include "pool.h"
  58. #include "volume.h"
  59. #include "logrecs.h"
  60. #include "trans.h"
  61. #include "openlog.h"
  62. #include "bitmap.h"
  63. #include "bf_extfuncs.h"
  64. #include "bm_extfuncs.h"
  65. #include "trans_extfuncs.h"
  66. #include "redo_intfuncs.h"
  67. #include "logaction.h"
  68. #include "util_funcs.h"
  69. #include "thread_globals.h"
  70. #include "bf_globals.h"
  71. #include "log_globals.h"
  72. #include "log_extfuncs.h"
  73. #include "sm_macro.h"
  74.  
  75.  
  76.  BOOL
  77. redoCheckPage (
  78.  
  79.     LOGRECORDHDR    *record,
  80.     GROUPLINK        **returnGroupLink,    /* return pointer to the page    */
  81.     PAGETYPE        pageType 
  82. )
  83. {
  84.  
  85.     PID                *pid;
  86.     DIRTYPAGEINFO    *dirtyInfo;
  87.     PAGE2SIZE        page2size;
  88.     LRC                *pageLRC;
  89.     GROUPLINK        *groupLink;    
  90.  
  91.     /*
  92.      *    get a pointer to the page for the record
  93.      */
  94.     pid = &(record->actionPid);
  95.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  96.  
  97.     /*
  98.      *    check to see if the page is in the dirty page list
  99.      */
  100.     if ((dirtyInfo = searchDirtyPageTable(pid)) == NULL)    {
  101.  
  102.         /*
  103.          *    don't need to redo
  104.          */
  105.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
  106.         return(FALSE);
  107.     }
  108.  
  109.     /*
  110.      *  check to see if the lrc on the page is greater than
  111.      *  the lrc in the log record.
  112.      *    Also check the lsn for the case of pages which never made it
  113.      *    back from the client.
  114.      */
  115.     if (CHECK_PAGE_LRC_LESS_DIRTYINFO(record->actionLRC, record->recordLSN, dirtyInfo)) {
  116.  
  117.         /*
  118.          *    don't need to redo
  119.          */
  120.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
  121.         return(FALSE);
  122.     }
  123.  
  124.     /*
  125.      *    Get the page size for this page type
  126.      */
  127.     switch (pageType) {
  128.     case PAGE_SLOTTED: page2size = SLOTTED_PAGE2SIZE;
  129.         break;
  130.     case PAGE_LARGENODE: page2size = LG_PAGE2SIZE;
  131.         break;
  132.     case PAGE_LARGEDATA: page2size = LGDATA_PAGE2SIZE;
  133.         break;
  134.     case PAGE_INDEX: page2size = BTREE_PAGE2SIZE;
  135.         break;
  136.     case PAGE_INDEXDESC: page2size = INDEXDESC_PAGE2SIZE;
  137.         break;
  138.     default:
  139.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  140.     }
  141.  
  142.     /*
  143.      *    read in the page
  144.      */
  145.     if ((groupLink = bf_ReadPage(UserBufGroup, pid, page2size, BF_SEM)) == NULL) {
  146.  
  147.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  148.     }
  149.  
  150.     /*
  151.      *    Get the lrc for this page type
  152.      */
  153.     switch (pageType) {
  154.     case PAGE_SLOTTED:
  155.         pageLRC = &( ((SLOTTEDPAGE*) groupLink->bufFrame)->header.lrc );
  156.         SM_ASSERT(LEVEL_1, !CHECK_SLOTTED_MAGIC((SLOTTEDPAGE*) groupLink->bufFrame));
  157.         break;
  158.     case PAGE_LARGENODE:
  159.         pageLRC = &( ((LGNODE*) (groupLink->bufFrame))->header.lrc );
  160.         CHECK_LARGENODE_MAGIC((LGNODE*) groupLink->bufFrame);
  161.         break;
  162.     case PAGE_LARGEDATA:
  163.         pageLRC = &( ((LGDATAPAGE*) groupLink->bufFrame)->header.lrc );
  164.         CHECK_LGDATAHDR_MAGIC((LGDATAPAGE*) groupLink->bufFrame);
  165.         break;
  166.     case PAGE_INDEX:
  167.         pageLRC = (LRC*)groupLink->bufFrame; /* lrc at beginning of page */
  168.         break;
  169.     case PAGE_INDEXDESC:
  170.         pageLRC = & ( ((INDEXDESCPAGE *) groupLink->bufFrame)->lrc );
  171.         break;
  172.     default:
  173.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  174.     }
  175.  
  176.     /*
  177.      *    See if the operation has been performed
  178.      */
  179.     if (compareLRC( &(record->actionLRC), pageLRC ) <= 0)  {
  180.  
  181.         /*
  182.          *    don't need to redo
  183.          */
  184.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
  185.         dirtyInfo->lrc = *pageLRC;
  186.  
  187.         /*
  188.          *    Release the page and return
  189.          */
  190.         signalSemaphore( &(groupLink->pageHash->semaphore) );
  191.         bf_UnfixPage(groupLink, BF_DEFAULT, FALSE);
  192.         return(FALSE);
  193.     }
  194.  
  195.     /*
  196.      *    Set up the firstLSN/LRC for the page
  197.      */
  198.     DEPEND_LOG(groupLink->pageHash, 0, &(record->recordLSN), &(record->actionLRC));
  199.  
  200.     /*
  201.      *    The operation needs to be redone.  Make sure that the
  202.      *    LRC difference is 1 (ie. nothing has been skipped).
  203.      */
  204. #ifdef DEBUG
  205. #ifdef INIT_LRC_IS_LSN
  206.     /*
  207.      *    This cannot be checked when lrc's are not always incremented
  208.      */
  209. #else
  210.     {
  211.         LRC                tempLRC;
  212.         tempLRC = pageLRC;
  213.         INCREMENT_LRC(&tempLRC);
  214.         SM_ASSERT(LEVEL_1, compareLRC(&(record->actionLRC), &tempLRC) == 0);
  215.     }
  216. #endif /* INIT_LRC_IS_LSN */
  217. #endif
  218.  
  219.     /*
  220.      *    Return the page
  221.      */
  222.     *returnGroupLink = groupLink;
  223.     return(TRUE);
  224. }
  225.